
class entry(object):
    
    VERBS = ["Edit Content"]
    PAGE = "<html><body>Hi There</body></html>"
    
    def __init__(self):
        self.page = self.PAGE
    
    def realize(self, event):
        self.realized = event
        if hasattr(event.shape, 'page'):
            self.page = event.shape.page
    
    def incoming(self, event):
        print event.data
        import os.path
        if self.page and self.page[0] == '@':
            pf = open(os.path.join(event.trail.root, self.page[1:]))
            page = pf.read()
        else:
            page = self.page
        length = len(page)
        event.trail.send_response(200)
        event.trail.send_header("Content-type", "text/html")
        event.trail.send_header("Content-Length", str(length))
        event.trail.end_headers()
        event.trail.wfile.write(page)

    def verb(self, event):
        import gtk
        d = gtk.MessageDialog(message_format = "Page",
            buttons = gtk.BUTTONS_OK_CANCEL)
        b = gtk.TextBuffer()
        e = gtk.TextView(b)
        sw = gtk.ScrolledWindow()
        sw.add_with_viewport(e)
        b.set_text(self.page)
        
        def fine(x,r):
            self.page = b.get_text(b.get_start_iter(), b.get_end_iter())
            self.realized.shape.page = self.page
            x.destroy()
        d.connect("response", fine)
        d.vbox.add(sw)
        e.show()
        sw.show()
        d.run()
        